﻿package Interface.TracksClasses
{
	import com.junkbyte.console.Cc;
	
	import caurina.transitions.Tweener;
	
	import flash.display.MovieClip;
	
	public class TracksScrollerContainer extends MovieClip
	{
		private const CItemPadding:int = 31;		
		private const CItemsPerPage:int = 7;
		private const CPageSize:int = 217;
		private const CTweenTime:int = 1;
		private const CY:int = 50;	
		
		private var FPagesCount:int;
		private var FItemsCount:int;
		private var FCurrentPage:int;
		
		public function TracksScrollerContainer():void 
		{
			FPagesCount = 0;
			FCurrentPage = 0;
			FItemsCount = 0;
		}
		
		public function MoveUp():void
		{
			if(FCurrentPage > 0)
			{
				FCurrentPage--;			
				Tweener.addTween(this, {y:GetY, time:CTweenTime, transition: "easeOutElastic"});
			}
		}
		
		public function MoveDown():void
		{				
			if(FCurrentPage < FPagesCount)			
			{								
				FCurrentPage++;				
				Tweener.addTween(this, {y:GetY, time:CTweenTime, transition: "easeOutElastic"});
			}
		}
		
		public function AddItem(AItem:TrackLabel):void
		{
			addChild(AItem);
			AItem.y = CItemPadding * FItemsCount;
			FItemsCount++;
			
			FPagesCount = Math.floor(FItemsCount / CItemsPerPage);
			if(FItemsCount % CItemsPerPage <= 0)
				FPagesCount = Math.max(FPagesCount - 1, 0);
		}
		
		private function get GetY():Number
		{
			return CY - FCurrentPage * CPageSize;
		}
				
		public function get IsFirstPage():Boolean
		{
			return FCurrentPage == 0;
		}
		
		public function get IsLastPage():Boolean
		{
			return FCurrentPage == FPagesCount;
		}
	}	
}
